'use strict'

let Fiber = require('fibers');
let https = require('https');

function get(options) {
    let fiber = Fiber.current;
    let error = null;
    let responseContent = null;

    var req = https.request(options, function(res) {
        res.on('data', function(d) {
            responseContent = d.toString('utf8');
            console.log(d);
            console.log(responseContent);
            fiber.run();
        });
    });
    req.end();

    req.on('error', function(e) {
        error = e;
        fiber.run();
    });

    Fiber.yield();

    if ( error ) {
        throw error;
    }

    return responseContent;
}

module.exports = {
    get: get
};
